package com.lunivore.stirry

import javafx.application.Platform
import javafx.scene.control.Button
import javafx.scene.control.Label
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test

class ButtonTest : AbstractExampleApplicationTest() {

    @Test
    fun `should be able to click a button`() {
        // Given a button that's going to set a flag when it's clicked
        var clicked: Boolean = false
        val button = Stirry.findInRoot<Button> { it.text == "Two" }.value

        button.onAction.also { clicked = true }


        // When we ask Stirry to click the button for us
        button.fireAndStir()

        val msg="button with text Two was clicked"
        val lbl=Stirry.findInRoot<Label> { it.text == "msg" }.value
        Platform.runLater {
            lbl.text=msg
        }
        Thread.sleep(5000)

        // Then it should wait for the button to be clicked
        Assertions.assertTrue(clicked)


    }
}

